<template>
  <div class="my_container">
    <div class="userAvatarBox">
      <div class="avatar">
        <img src="/miaomiao/images/movie_2.jpg" alt />
      </div>
    </div>
    <van-cell-group>
      <van-cell title="用户名" :value="$store.state.username" />
      <van-cell
        title="用户角色"
        :value="$store.state.role==='admin'?'管理员':'普通用户'"
        is-link
        @click="toAdmin"
      />
      <van-cell title="我的订单" value />
      <van-cell title="我的服务" value />
      <van-cell title="设置" value />
    </van-cell-group>
    <van-button round type="danger" size="large" @click="logout" class="logoutBtn">退出登录</van-button>
  </div>
</template>

<script>
export default {
  name: 'userCenter',
  data() {
    return {}
  },
  methods: {
    async logout() {
      let res = await this.$axios.get('/api2/users/logout')
      if (res.status == 0) {
        this.$toast('退出成功')
        setTimeout(() => {
          this.$router.push('/mine/login')
          this.$store.commit('DEL_UNAME')
          this.$store.commit('DEL_ROLE')
        }, 1000)
      }
    },
    toAdmin() {
      if (this.$store.state.role !== 'admin') return
      this.$router.push('/admin')
    }
  }
}
</script>

<style scoped>
.my_container {
  padding-top: 51px;
}
.logoutBtn {
  width: 80%;
  display: block;
  margin: 10px auto;
}
.userAvatarBox {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 120px;
  background: url('/miaomiao/images/avatarBg.jpg') no-repeat 0 0;
}
.avatar {
  width: 70px;
  height: 70px;
  border: 1px solid #fff;
  border-radius: 50%;
  overflow: hidden;
}
.avatar img {
  width: 100%;
}
</style>
